﻿using System;
using System.Collections;

namespace NetTopologySuite.Features
{
	[Serializable]
	public class AttributesTable : IAttributesTable
	{
		public int Count
		{
			get
			{
				return this._attributes.Count;
			}
		}

		public string[] GetNames()
		{
			int num = 0;
			string[] array = new string[this._attributes.Count];
			foreach (object obj in this._attributes.Keys)
			{
				string text = (string)obj;
				array[num++] = text;
			}
			return array;
		}

		public object[] GetValues()
		{
			int num = 0;
			object[] array = new object[this._attributes.Count];
			foreach (object obj in this._attributes.Values)
			{
				array[num++] = obj;
			}
			return array;
		}

		public bool Exists(string attributeName)
		{
			return this._attributes.ContainsKey(attributeName);
		}

		public void AddAttribute(string attributeName, object attributeValue)
		{
			if (this.Exists(attributeName))
			{
				throw new ArgumentException("Attribute " + attributeName + " already exists!");
			}
			this._attributes.Add(attributeName, attributeValue);
		}

		public virtual void DeleteAttribute(string attributeName)
		{
			if (!this.Exists(attributeName))
			{
				throw new ArgumentException("Attribute " + attributeName + " not exists!");
			}
			this._attributes.Remove(attributeName);
		}

		public Type GetType(string attributeName)
		{
			if (!this.Exists(attributeName))
			{
				throw new ArgumentException("Attribute " + attributeName + " not exists!");
			}
			if (this._attributes[attributeName] == null)
			{
				return typeof(object);
			}
			return this._attributes[attributeName].GetType();
		}

		protected object GetValue(string attributeName)
		{
			if (!this.Exists(attributeName))
			{
				throw new ArgumentException("Attribute " + attributeName + " not exists!");
			}
			return this._attributes[attributeName];
		}

		protected void SetValue(string attributeName, object attributeValue)
		{
			if (!this.Exists(attributeName))
			{
				throw new ArgumentException("Attribute " + attributeName + " not exists!");
			}
			this._attributes[attributeName] = attributeValue;
		}

		public object this[string attributeName]
		{
			get
			{
				return this.GetValue(attributeName);
			}
			set
			{
				this.SetValue(attributeName, value);
			}
		}

		private readonly Hashtable _attributes = new Hashtable();
	}
}
